package good

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"
	"homepage_srv/homepageclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddReplyLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddReplyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddReplyLogic {
	return &AddReplyLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 二级评论添加
func (l *AddReplyLogic) AddReply(req *types.AddReplyRequest) (resp *types.Response, err error) {
	reply, err := l.svcCtx.HomepageGrpc.AddReply(l.ctx, &homepageclient.AddReplyRequest{
		CommentId: req.CommentId,
		UserId:    req.UserId,
		Content:   req.Content,
	})
	if err != nil {
		return respons.Error(400, "服务端错误", err.Error()), err
	}

	return respons.Success(reply), nil
}
